package com.boe.common.util.freemark.base;

import com.boe.common.util.AnnotationUtil;
import com.boe.common.util.StringUtil;
import com.boe.common.util.freemark.BaseMethodModelFreemarker;
import com.boe.common.util.freemark.P0Error;
import freemarker.template.TemplateModelException;
import lombok.*;

import java.lang.reflect.Field;
import java.util.List;


public class FreemarkerFieldDbTableField extends BaseMethodModelFreemarker {
    @Override
    public Object exec(List list) throws TemplateModelException {
        var paramValue = getFreemarkerParameter(list.get(0));
        if (paramValue instanceof Field) {
            return StringUtil.asString(AnnotationUtil.getTableField((Field) paramValue), ((Field) paramValue).getName());
        }
        throw new P0Error(paramValue);
    }
}
